package com.mmd.manage.service.impl;

import com.mmd.bean.CODE;
import com.mmd.common.entity.MmdVat;
import com.mmd.exception.GameException;
import com.mmd.manage.dao.MmdVatDao;
import com.mmd.manage.service.VatService;
import com.mmd.manage.vo.VatEo;
import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.Date;

@Service
public class VatServiceImpl implements VatService {
	@Autowired
	private MmdVatDao mmdVatDao;

	@Override
	public boolean addVat(VatEo eo) {
		MmdVat mmdVat = mmdVatDao.selectByPrimaryKey(eo.getAccount());
		if (mmdVat != null) {
			throw new GameException(new CODE(9999, "已新增VAT"));
		}
		MmdVat mv = new MmdVat();
		BeanUtils.copyProperties(eo, mv);
		mv.setCreateTime(new Date());
		return mmdVatDao.insert(mv)==1;
	}

	@Override
	public boolean modifyVat(VatEo eo) {
		MmdVat mv = new MmdVat();
		BeanUtils.copyProperties(eo, mv);
		return mmdVatDao.updateByPrimaryKeySelective(mv)==1;
	}

	@Override
	public MmdVat getVatByAccount(String account) {
		return mmdVatDao.selectByPrimaryKey(account);
	}
}
